@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

:root {
  --bg-color: #121212;
  --bg-color-offset: #1a1a1a;
  --card-bg: #242424;
  --input-bg: #2a2a2a;
  --text-color: rgba(255, 255, 255, 0.87);
  --text-color-light: #aaa;
  --primary-color: #646cff;
  --primary-color-hover: #747bff;
  --border-color: #3a3a3a;
  --focus-ring-color: rgba(100, 108, 255, 0.5);
  --shadow-color: rgba(0, 0, 0, 0.2);
  --card-shadow: 0 4px 6px -1px var(--shadow-color), 0 2px 4px -2px var(--shadow-color);
  --popover-shadow: 0 10px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.4);
  --border-radius-sm: 4px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --transition-speed: 0.2s;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-container { max-width: 1800px; margin: 0 auto; padding: 2rem 2.5rem; }

.header { text-align: center; margin-bottom: 2rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border-color); }
.header h1 { font-size: 2.8rem; font-weight: 700; color: var(--primary-color); margin: 0; }
.header p { margin-top: 0.5rem; color: var(--text-color-light); font-size: 1rem; }

.tabs { display: flex; justify-content: center; gap: 1rem; margin-bottom: 2rem; }
.tab-button { padding: 0.75rem 1.5rem; font-size: 1rem; font-weight: 500; cursor: pointer; background: transparent; color: var(--text-color-light); border: none; border-bottom: 2px solid transparent; border-radius: 0; transition: all var(--transition-speed) ease; }
.tab-button:hover { color: var(--text-color); }
.tab-button.active { color: var(--primary-color-hover); border-bottom-color: var(--primary-color-hover); font-weight: 700; }

.content { background: var(--card-bg); padding: 2.5rem; border-radius: var(--border-radius-lg); border: 1px solid var(--border-color); box-shadow: var(--card-shadow); }

.input-section { margin-bottom: 2.5rem; }
.components-section, .properties-section { margin-bottom: 0; }
.components-section h2, .properties-section h2 { 
    font-size: 1.25rem; 
    font-weight: 700; 
    margin-top: 0;
    margin-bottom: 1.5rem; 
    padding-bottom: 1rem; 
    border-bottom: 1px solid var(--border-color); 
}

.input-mode-selector { display: flex; justify-content: space-between; align-items: center; background-color: var(--bg-color-offset); padding: 1rem; border-radius: var(--border-radius-md); margin-bottom: 1.5rem; }
.input-mode-selector label { font-weight: 500; color: var(--text-color); }
.input-mode-selector div { display: flex; gap: 0.5rem; background-color: var(--bg-color); padding: 0.25rem; border-radius: var(--border-radius-sm); }
.mode-btn { padding: 0.5rem 1rem; border: none; background: transparent; color: var(--text-color-light); cursor: pointer; border-radius: var(--border-radius-sm); transition: all var(--transition-speed); }
.mode-btn:hover { color: var(--text-color); }
.mode-btn.active { background: var(--primary-color); color: white; font-weight: 700; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

.input-area-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 2rem; align-items: start; }

.ketcher-wrapper { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.ketcher-container { height: 500px; border: 1px solid var(--border-color); border-radius: var(--border-radius-md); overflow: hidden; box-shadow: inset 0 2px 4px var(--shadow-color); }
.sync-btn { align-self: center; padding: 0.75rem 1.5rem; background: var(--primary-color-hover); color: white; border: none; border-radius: var(--border-radius-md); font-size: 1rem; font-weight: 700; cursor: pointer; transition: all var(--transition-speed); }
.sync-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(100, 108, 255, 0.2); }

.viewer-wrapper { display: flex; flex-direction: column; background-color: var(--bg-color); padding: 1rem; border-radius: var(--border-radius-md); border: 1px solid var(--border-color); height: 500px; }
.viewer-wrapper h3 { margin-top: 0; margin-bottom: 1rem; text-align: center; font-weight: 500; color: var(--text-color-light); }
.viewer-container-3d { flex: 1; min-height: 0; background-color: var(--bg-color-offset); border-radius: var(--border-radius-sm); overflow: hidden; }
.viewer-note { text-align: center; font-size: 0.9rem; color: var(--text-color-light); margin-top: 1rem; margin-bottom: 0; }

.smiles-input-wrapper { display: flex; flex-direction: column; gap: 0.75rem; }
.smiles-input-wrapper label { font-weight: 500; }
.smiles-textarea { width: 100%; min-height: 500px; padding: 0.8rem 1rem; background: var(--input-bg); border: 1px solid var(--border-color); color: var(--text-color); border-radius: var(--border-radius-md); font-size: 1rem; font-family: 'Courier New', Courier, monospace; resize: vertical; transition: border-color var(--transition-speed), box-shadow var(--transition-speed); }
.smiles-textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px var(--focus-ring-color); }

.components-list { display: flex; flex-direction: column; gap: 1rem; }
.component-card { background: var(--bg-color-offset); padding: 1rem 1.5rem; border-radius: var(--border-radius-md); border-left: 4px solid var(--primary-color); }
.component-info { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.component-index { font-weight: 700; color: var(--primary-color-hover); font-size: 1rem; }
.component-smiles { background: var(--input-bg); padding: 0.3rem 0.6rem; border-radius: var(--border-radius-sm); color: var(--text-color); font-family: 'Courier New', Courier, monospace; font-size: 0.9em; flex-grow: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.component-slider { display: flex; align-items: center; gap: 1rem; }
.component-ratio { font-family: 'Courier New', Courier, monospace; font-weight: 700; font-size: 1.1rem; color: var(--text-color); min-width: 60px; text-align: right; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 8px; background: var(--input-bg); border-radius: 5px; outline: none; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: var(--primary-color); border-radius: 50%; border: 3px solid var(--card-bg); transition: background-color var(--transition-speed); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: var(--primary-color); border-radius: 50%; border: 3px solid var(--card-bg); transition: background-color var(--transition-speed); }
input[type="range"]:hover::-webkit-slider-thumb, input[type="range"]:hover::-moz-range-thumb { background: var(--primary-color-hover); }

.properties-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem 2rem; }
.property-category h3 { color: var(--primary-color-hover); border-bottom: 1px solid var(--border-color); padding-bottom: 0.75rem; margin-bottom: 1rem; font-size: 1.1rem; font-weight: 500; }
.checkbox-label { display: flex; align-items: center; gap: 0.75rem; cursor: pointer; margin-bottom: 0.75rem; padding: 0.25rem; border-radius: var(--border-radius-sm); transition: background-color var(--transition-speed); }
.checkbox-label:hover { background-color: var(--input-bg); }
.checkbox-label input[type="checkbox"] { -webkit-appearance: none; appearance: none; background-color: var(--input-bg); margin: 0; font: inherit; color: var(--text-color); width: 1.15em; height: 1.15em; border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); transform: translateY(-0.075em); display: grid; place-content: center; transition: all var(--transition-speed) ease; }
.checkbox-label input[type="checkbox"]::before { content: ""; width: 0.65em; height: 0.65em; transform: scale(0); transition: 120ms transform ease-in-out; box-shadow: inset 1em 1em var(--primary-color); transform-origin: center; clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%); }
.checkbox-label input[type="checkbox"]:checked { border-color: var(--primary-color); }
.checkbox-label input[type="checkbox"]:checked::before { transform: scale(1); }
.checkbox-label input[type="checkbox"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring-color); }

.controls-section {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 1rem;
    align-items: center;
    margin-top: 1rem;
    margin-bottom: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

/* --- MODIFICATION START: Style adjustments for dynamic buttons --- */
.control-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
    background: var(--bg-color-offset);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    
    /* Additions for better dynamic content handling */
    min-width: 180px; /* Provides a stable base width */
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* --- MODIFICATION END --- */

.control-btn:hover:not(:disabled) {
    background: var(--input-bg);
    border-color: var(--primary-color);
    color: var(--primary-color-hover);
}
.control-btn:disabled {
    color: var(--text-color-light);
    background-color: var(--bg-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.calculate-btn { 
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 700; 
    color: white; 
    background: var(--primary-color); 
    border: none; 
    border-radius: var(--border-radius-md); 
    cursor: pointer; 
    transition: all var(--transition-speed) ease; 
    display: flex; align-items: center; justify-content: center; gap: 0.75rem; 
}
.calculate-btn:hover:not(:disabled) { background: var(--primary-color-hover); transform: translateY(-2px); box-shadow: 0 4px 8px rgba(100, 108, 255, 0.2); }
.calculate-btn:disabled { background-color: #333; color: var(--text-color-light); cursor: not-allowed; }

.popover-container {
    position: relative;
    display: inline-block;
}

.popover-content {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    z-index: 1000;
    margin-bottom: 10px;
    
    background: var(--bg-color-offset);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--popover-shadow);
    padding: 1.5rem;
    width: 500px;
    max-width: 90vw;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

.popover-content.wide {
    width: 800px;
}

.popover-content.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.results-section { margin-top: 0; background: var(--bg-color-offset); padding: 2rem; border-radius: var(--border-radius-md); border-left: 4px solid var(--primary-color); min-height: 100px; }
.results-section h2.results-title { margin-top: 0; margin-bottom: 1.5rem; font-size: 1.5rem; font-weight: 700; }
.results-placeholder { color: var(--text-color-light); text-align: center; padding: 2rem 0; }
.error-message { color: #ff6b6b; font-weight: bold; text-align: center; padding: 2rem 0; }
.result-item { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 0; border-bottom: 1px solid var(--border-color); font-size: 1rem; }
.result-item:last-child { border-bottom: none; }
.result-key { font-weight: 500; color: var(--text-color-light); }
.result-value { color: var(--primary-color-hover); font-weight: 700; font-family: 'Courier New', Courier, monospace; }

.readme-content { line-height: 1.8; }
.readme-content h3 { color: var(--primary-color); margin-top: 2rem; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border-color); }
.readme-content code { background: var(--input-bg); padding: 0.2rem 0.5rem; border-radius: var(--border-radius-sm); font-family: 'Courier New', Courier, monospace; font-size: 0.95em; border: 1px solid var(--border-color); }
.readme-content p { margin-bottom: 1rem; }
.readme-content ul { padding-left: 20px; }

.spinner { border: 2px solid rgba(255, 255, 255, 0.3); border-top: 2px solid white; border-radius: 50%; width: 18px; height: 18px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

@media (max-width: 1200px) { 
    .input-area-grid {
        grid-template-columns: 1fr;
    }
    .ketcher-container, .viewer-wrapper, .smiles-textarea {
        height: 400px;
    }
}

@media (max-width: 768px) {
  .app-container { padding: 1.5rem 1rem; }
  .header h1 { font-size: 2.2rem; }
  .content, .results-section, .readme-content { padding: 1.5rem; }
  .input-mode-selector { flex-direction: column; gap: 1rem; }
  .component-info { flex-direction: column; align-items: flex-start; }
  .controls-section {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .popover-content {
    left: 0;
    transform: translateX(0) translateY(10px);
  }
  .popover-content.visible {
    transform: translateX(0) translateY(0);
  }
}